package com.dongdongshop.controller;

import com.dongdongshop.domain.AjaxResult;
import com.dongdongshop.em.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("sellerController")
public class SellerController {

    @DubboReference
    private SellerService sellerService;

    //查询全部商家信息
    @RequestMapping("getSellerList")
    @ResponseBody
    public AjaxResult<List<TbSeller>> getSellerList(String name, String nickName) {
        try {
            List<TbSeller> list = sellerService.getSellerList(name, nickName);
            return AjaxResult.OK().setData(list);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }

    //回显商家信息进行审核
    @RequestMapping("getSellerBySellerId")
    @ResponseBody
    public AjaxResult<TbSeller> getSellerBySellerId(String sellerId) {
        if (sellerId == null && "".equals(sellerId)) {
            return AjaxResult.R(ResultEnum.PARAMETER_EMPTY);
        }
        try {
            TbSeller seller = sellerService.getSellerBySellerId(sellerId);
            return AjaxResult.OK().setData(seller);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }

    //商家审核
    @RequestMapping("updateAudit")
    @ResponseBody
    public AjaxResult updateAudit(String sellerId,String status){

        if (sellerId == null && status == null){
            return AjaxResult.R(ResultEnum.PARAMETER_EMPTY);
        }
        try {
            sellerService.updateAudit(sellerId,status);
            return AjaxResult.OK();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.ERROR();
        }
    }
}
